package com.gok.einvoice.framework.web.service;

import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;

import java.io.File;
import java.io.IOException;

public class InvoiceRecognizer{
    public String recognizeInvoice(File file) throws IOException {
        Tika tika = new Tika();
        try {
            return tika.parseToString(file);
        } catch (TikaException e) {
            e.printStackTrace();
        }
        return "你们";
    }

    public boolean validateInvoice(String invoiceData) {
        // 假设我们有一个验证API
        String apiUrl = "http://example.com/validate";
        // 此处添加实际的API调用与验证逻辑
        return true; // 仅作为示例
    }

    public void processInvoice(File file) {
        try {
            String invoiceData = recognizeInvoice(file);
            boolean isValid = validateInvoice(invoiceData);
            System.out.println("发票识别数据: " + invoiceData);
            System.out.println("发票验证结果: " + (isValid? "有效" : "无效"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        InvoiceRecognizer recognizer = new InvoiceRecognizer();
        recognizer.processInvoice(new File("C:\\Users\\28580\\Desktop\\1737017710065.jpg"));
    }
}